package com.googlecode.jyoutubeuploader.archive;


/* INSTRUCTION: This is a command line application. So please execute this template with the following arguments:

		arg[0] = YouTube account username whose videos' list you want to see
*/

/**
 * @author (Your Name Here)
 *
 */
 
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.data.youtube.VideoEntry;
import com.google.gdata.data.youtube.VideoFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
 * This is a test template
 */

  public class YouTube {
    
    public static void main(String[] args) {
      
      try {
        
        // Create a new YouTube service
        YouTubeService myService = new YouTubeService("My Application");
        
        // Get a list of all entries
        URL metafeedUrl = new URL("http://gdata.youtube.com/feeds/api/users/"+args[0]+"/favorites");
        System.out.println("Getting favorite video entries...\n");
        VideoFeed resultFeed = myService.getFeed(metafeedUrl, VideoFeed.class);
        List<VideoEntry> entries = resultFeed.getEntries();
        for(int i=0; i<entries.size(); i++) {
          VideoEntry entry = entries.get(i);
          System.out.println("\t" + entry.getTitle().getPlainText());
        }
        System.out.println("\nTotal Entries: "+entries.size());
      }
      catch(AuthenticationException e) {
        e.printStackTrace();
      }
      catch(MalformedURLException e) {
        e.printStackTrace();
      }
      catch(ServiceException e) {
        e.printStackTrace();
      }
      catch(IOException e) {
        e.printStackTrace();
      }
    }
  }
